package qianting.news.user.service.impl;

import cn.hutool.crypto.digest.DigestUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import qianting.news.apis.models.user.pojos.ApUser;
import qianting.news.user.mapper.ApUserMapper;
import qianting.news.user.service.ApUserService;

@Service
@Transactional
@Slf4j
public class ApUserServiceImpl extends ServiceImpl<ApUserMapper, ApUser> implements ApUserService {

    @Autowired
    private ApUserMapper apUserMapper;

    //根据id修改用户名
    @Override
    public boolean updateUsername(Long id, String username) {

        return apUserMapper.updateUsernameById(id, username);

    }

    //根据id修改密码
    @Override
    public boolean updatePassword(Long id, String password) {

        String salt = apUserMapper.getSaltById(id);
        String pswd_md5 = DigestUtil.sha256Hex(password + salt);
        return apUserMapper.updatePasswordById(id, pswd_md5);

    }

    //获取盐
    @Override
    public String getSalt(Long id) {

        return apUserMapper.getSaltById(id);

    }

    @Override
    public boolean editUserPortrait(Long id, String filename) {

        return apUserMapper.editUserPortraitById(id,filename);

    }
}
